package com.hzncc.flowable_diboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diboot.core.vo.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.diboot.core.service.impl.BaseServiceImpl;

import com.hzncc.flowable_diboot.entity.EquipmentTeam;
import com.hzncc.flowable_diboot.mapper.EquipmentTeamMapper;
import com.hzncc.flowable_diboot.service.EquipmentTeamService;


/**
* 设备团队 相关Service实现类
* @author MyName
* @version 1.0
* @date 2024-06-28
* Copyright © MyCorp
*/
@Slf4j
@Service
public class EquipmentTeamServiceImpl extends BaseServiceImpl<EquipmentTeamMapper, EquipmentTeam> implements EquipmentTeamService {
    @Autowired
    private EquipmentTeamMapper equipmentTeamMapper;


    @Override
    public JsonResult addEquipmentTeamMember(String createBy,String machineNumber) {
        QueryWrapper<EquipmentTeam> qw = new QueryWrapper<>();
        qw.eq("member", createBy);
        qw.eq("machine_number",machineNumber);
        qw.eq("is_deleted", 0);
        EquipmentTeam selectOne = equipmentTeamMapper.selectOne(qw);
        EquipmentTeam equipmentTeam = equipmentTeamMapper.selUserInfo(createBy);
        if ( selectOne != null ){
            super.deleteEntity(selectOne);
        }
        equipmentTeam.setMachineNumber(machineNumber);
        equipmentTeam.setMember(createBy);
        boolean teamServiceEntity = super.createEntity(equipmentTeam);
        return JsonResult.OK(teamServiceEntity);
    }

    @Override
    public JsonResult addMatterTeamMember(String createBy,String emId) {
        QueryWrapper<EquipmentTeam> qw = new QueryWrapper<>();
        qw.eq("member", createBy);
        qw.eq("em_id",emId);
        qw.eq("is_deleted", 0);
        EquipmentTeam selectOne = equipmentTeamMapper.selectOne(qw);
        EquipmentTeam equipmentTeam = equipmentTeamMapper.selUserInfo(createBy);
        if ( selectOne != null ){
            super.deleteEntity(selectOne);
        }
        equipmentTeam.setEmId(emId);
        equipmentTeam.setMember(createBy);
        boolean teamServiceEntity = super.createEntity(equipmentTeam);
        return JsonResult.OK(teamServiceEntity);
    }
}